package stack;

import java.util.Stack;

/*
 *@description 最小栈
 *@author hkfan
 *@version 1.0
 *@create 2025/6/6 15:29
 */
public class LeetCode_155 {
    class MinStack {

        Stack<Node> stack;

        private class Node{
            int value;
            int minValue;

            public Node(int value, int minValue) {
                this.value = value;
                this.minValue = minValue;
            }
        }

        public MinStack() {
            stack = new Stack<>();
        }

        public void push(int val) {
            int temp = Integer.MAX_VALUE;
            if (!stack.isEmpty()){
                temp=stack.peek().minValue;
            }
            stack.add(new Node(val,Math.min(val,temp)));
        }

        public void pop() {
            stack.pop();
        }

        public int top() {
            return stack.peek().value;
        }

        public int getMin() {
            return stack.peek().minValue;
        }
    }

}
